using System;
using System.Text;
using Microsoft.Practices.RecipeFramework;
using Microsoft.Practices.ComponentModel;
using EnvDTE;

namespace SPALM.SharePointSoftwareFactory.Library.ValueProviders
{
    /// <summary>
    /// Provides the type of template which is used in the project, either VSEWSS-Format or HIVE Format
    /// </summary>
    [ServiceDependency(typeof(DTE))]
    public class IsVSEWSSTemplateTypeValueProvider : ValueProvider
    {
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            if (currentValue != null)
            {
                newValue = null;
                return false;
            }

            DTE service = (DTE)this.GetService(typeof(DTE));
            Project project = Helpers.GetSelectedProject(service);

            if (project == null)
            {
              //find first project
              foreach (Project p in Helpers.GetAllProjects(service))
              {
                if (Helpers2.IsVSTemplate(service, p))
                {
                  newValue = true; // Helpers2.IsVSTemplate(service, project);
                  return true;
                }
              }
            }

            if (project == null)
            {
              //no project select but no project there which VSTemplate then it must be HIVE
              newValue = false;
              return true;
            }

            newValue = Helpers2.IsVSTemplate(service, project);
            return true;
        }      
    }
}
